
package com.shop.cloud.upms.admin.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.cloud.upms.admin.service.SysTenantPackageCostService;
import com.shop.cloud.upms.admin.service.SysTenantPackageMenuService;
import com.shop.cloud.upms.common.entity.SysTenantPackage;
import com.shop.cloud.upms.admin.mapper.SysTenantPackageMapper;
import com.shop.cloud.upms.admin.service.SysTenantPackageService;
import com.shop.cloud.upms.common.entity.SysTenantPackageCost;
import com.shop.cloud.upms.common.entity.SysTenantPackageMenu;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;

/**
 * 租户套餐
 *
 * @author 
 * @date 2023-12-25 11:12:41
 */
@Service
@AllArgsConstructor
public class SysTenantPackageServiceImpl extends ServiceImpl<SysTenantPackageMapper, SysTenantPackage> implements SysTenantPackageService {

    private final SysTenantPackageCostService sysTenantPackageCostService;
    private final SysTenantPackageMenuService sysTenantPackageMenuService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean removeById(Serializable id) {
        sysTenantPackageCostService.remove(Wrappers.<SysTenantPackageCost>query().lambda()
                .eq(SysTenantPackageCost::getPackageId, id));
        sysTenantPackageMenuService.removeById(id);
        return super.removeById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean save(SysTenantPackage entity) {
        super.save(entity);
        SysTenantPackageMenu sysTenantPackageMenu = new SysTenantPackageMenu();
        sysTenantPackageMenu.setPackageId(entity.getId());
        sysTenantPackageMenu.setMenuIds(new String[]{});
        sysTenantPackageMenuService.save(sysTenantPackageMenu);
        return Boolean.TRUE;
    }
}
